import { Route, Router, Redirect, IndexRoute } from 'react-router';
import { Provider } from 'react-redux';
//import BrowserHistory from 'react-router/lib/BrowserHistory';
//import HashHistory from 'react-router/lib/HashHistory';
import createBrowserHistory from 'history/lib/createBrowserHistory';
import createHashHistory from 'history/lib/createHashHistory';
import Modernizr from 'modernizr';
//import Blank from 'routes/blank';
import App from './routes/app';
import Base from './common/base';
import Dummy from './common/dummy';
import Index from './routes/index';
import Login from './routes/login';
import User from 'routes/user/index';
import UserList from 'routes/user/list';
import UserAdd from 'routes/user/add';
import UserView from 'routes/user/view';
import Role from 'routes/role/index';
import RoleList from 'routes/role/list';
import RoleAdd from 'routes/role/add';
import RoleView from 'routes/role/view';
import store from './stores/store';
import history from './common/history';

export default (withHistory, onUpdate) => {
    //const history = withHistory ?
    //    (Modernizr.history ?
    //        createBrowserHistory()
    //        : createHashHistory())
    //    : null;
    return (
        <Provider store={store}>
            {() =>
            <Router history={history} onUpdate={onUpdate}>
                <Redirect from='/' to="/dashboard" />
                <Route path='/' component={App} >
                    <Route component={Base} >
                        <Route path='dashboard' component={Index} />
                        <Redirect from='/user' to="/user/list" />
                        <Route path='user' component={User} >
                            <Route path='list' component={UserList} />
                            <Route path='add' component={UserAdd} />
                            <Route path=':id' component={UserView} />
                        </Route>
                        <Redirect from='/role' to="/role/list" />
                        <Route path='role' component={Role} >
                            <Route path='list' component={RoleList} />
                            <Route path='add' component={RoleAdd} />
                            <Route path=':id' component={RoleView} />
                        </Route>
                    </Route>
                    <Route component={Dummy}>
                        <Route path='login' component={Login} />
                    </Route>
                </Route>
            </Router>}
        </Provider>
    );
};
